﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HitachiLib.Data;

namespace HitachiApp.Model
{
    public class ScheduleUnitDayControlModel : ScheduleUnitBaseModel, INotifyPropertyChanged
    {
        DateTime dt;
        ScheduleTabViewModel parent;
        List<ScheduleUnitTimeControlModel> unit_time = new List<ScheduleUnitTimeControlModel>();

        public ScheduleUnitDayControlModel(DateTime datetime, int type, ScheduleTabViewModel parent_model)
            : base(type)
        {
            parent = parent_model;
            dt = datetime;
            unit_time.Add(new ScheduleUnitTimeControlModel(dt.AddHours(6), type, parent_model));
            unit_time.Add(new ScheduleUnitTimeControlModel(dt.AddHours(12), type, parent_model));
            unit_time.Add(new ScheduleUnitTimeControlModel(dt.AddHours(18), type, parent_model));
        }

        public ScheduleUnitTimeControlModel Morning
        {
            get { return unit_time[0]; }
        }
        public ScheduleUnitTimeControlModel Afternoon
        {
            get { return unit_time[1]; }
        }
        public ScheduleUnitTimeControlModel Evening
        {
            get { return unit_time[2]; }
        }
        public DateTime StartTime
        {
            get { return dt; }
        }

        public int Size
        {
            get { return Morning.Size + Afternoon.Size + Evening.Size; }
        }

        public void Clear()
        {
            unit_time[0].Clear();
            unit_time[1].Clear();
            unit_time[2].Clear();
            RaisePropertyChanged("Size");
        }

        public void Cleanup()
        {
            unit_time[0].Cleanup();
            unit_time[1].Cleanup();
            unit_time[2].Cleanup();
            RaisePropertyChanged("Size");
        }

        public void Add(ViewItem vi)
        {
            Project p = vi.Project;
            Schedule s = GetSchedule(p);
            int h = s.PlanDate.Hour;
            switch (h)
            {
                case Schedule.TimeMorning:
                    Morning.Add(vi);
                    break;
                case Schedule.TimeAfternoon:
                    Afternoon.Add(vi);
                    break;
                default:
                    Evening.Add(vi);
                    break;
            }
            RaisePropertyChanged("Size");
        }

        #region PropertChanged Block
        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
        #endregion
    }
}
